package com.auicyh.tylb.comm;

import java.io.File;
import java.util.Vector;

/**
 * 作者：  Ocean 2017/11/3 14:24
 * 功能：  串口驱动类
 * Q Q：   1126067113
 * <p>
 * http://gqdy365.iteye.com/blog/2188906
 * http://blog.csdn.net/wodeluoye/article/details/49368529
 * https://code.google.com/p/android-serialport-api/
 * <p>
 * 修改：
 *
 * @author Ocean
 */

public class SerialDriver {
    /** 驱动名 */
    private String mDriverName;
    /** 设备根目录 */
    private String mDeviceRoot;
    /** 设备列表(使用向量类) */
    private Vector<File> mDevices = null;

    public SerialDriver() {
    }

    /**
     * @param driverName 名字
     * @param deviceRoot 设备根目录
     */
    public SerialDriver(String driverName, String deviceRoot) {
        mDriverName = driverName;
        mDeviceRoot = deviceRoot;
    }

    public Vector<File> getDrivers() {
        if (mDevices == null) {
            mDevices = new Vector<>();
            // "/dev"是Linux设备文件目录
            File dev = new File("/dev");
            File[] files = dev.listFiles();
            for (File file : files) {
                // startsWith 指定的前缀开始
                if (file.getAbsolutePath().startsWith(mDeviceRoot)) {
                    mDevices.add(file);
                }
            }
        }
        return mDevices;
    }

    public String getDriverName() {
        return mDriverName;
    }

    public void setDriverName(String driverName) {
        mDriverName = driverName;
    }

    public String getDeviceRoot() {
        return mDeviceRoot;
    }

    public void setDeviceRoot(String deviceRoot) {
        mDeviceRoot = deviceRoot;
    }
}
